﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using NeuralNetworks.Networks;
using NeuralNetworks.Layers;
using NeuralNetworks.Neurons;

namespace NeuralNetworks
{
    class BiasPanel : Panel
    {
        //private Label nameLabel;
        private TextBox weightBox;

        //public ActivationNetwork ActivationNetwork;
        private int layerNo;
        //private Layer layer;
        private Neuron neuron;

        public Neuron Neuron { get { return neuron; } }

        public double Weight
        {
            get
            {
                double w = 999999999.0;
                try
                {
                    w = Double.Parse(weightBox.Text);
                    return w;
                }
                catch (System.FormatException)
                {
                    MessageBox.Show("Błędny format wagi biasu (warstwa = " + layerNo +"). \nPopraw i spróbuj ponownie.");
                    return 99999.0;
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Błąd wprowadzonej wagi biasu (warstwa = " + layerNo +").\n\n" + exception.Message);
                    return 99999.0;
                }
            }
        }

        public BiasPanel(Neuron neuron)
            : base()
        {
            //this.layerNo = layerNo;
            //this.layer = layer;
            /*nameLabel = new Label();
            nameLabel.Size = new Size(35, 15);
            nameLabel.Location = new Point(0, 0);
            // format: C [neuron poprzedniej warstwy] -> [neuron aktualnej warstwy]
            nameLabel.Text = "B" + this.layerNo.ToString();
            nameLabel.BackColor = Color.Coral;*/

            this.neuron = neuron;

            weightBox = new TextBox();
            weightBox.Size = new Size(35, 20);
            //weightBox.Location = new Point(0, 15);
            weightBox.Location = new Point(0, 0);
            weightBox.Text = neuron.BiasWeight.ToString();

            //this.Controls.Add(nameLabel);
            this.Controls.Add(weightBox);
            //this.Size = new Size(35, 35);
            this.Size = new Size(35, 20);
        }
    }
}
